//表单管理功能接口
import { useAxios } from '@/hooks/web/useAxios'

const request = useAxios()

/**
 * 查询表单
 */
export const queryForm = (data) => {
  return request.post({
    url: 'form/form/query',
    data
  })
}

/**
 * 从实体创建表单
 */
export const createFromEntity = (data) => {
  return request.post({
    url: 'form/form/createFromEntity',
    data
  })
}

/**
 * @description  查询单个表单
 */
export const getForm = (id) => {
  return request.postXww({
    url: 'form/form/get',
    params: { pkId: id }
  })
}

/**
 * @description 根据实体列重新生成表单控件
 */
export const getControlsFromEntity = (formId, entityId) => {
  return request.postXww({
    url: 'form/form/getControlsFromEntity',
    params: { formId: formId, entityId: entityId }
  })
}

/**
 * @description  发布表单
 */
export const publishForm = (formId) => {
  return request.postXww({
    url: 'form/form/publish',
    params: { formId: formId }
  })
}

/**
 * @description  删除表单
 */
export const delForm = (id) => {
  return request.postXww({
    url: 'form/form/delete',
    params: { pkId: id }
  })
}

/**
 * @description 保存表单
 */
export const saveForm = (data) => {
  return request.post({
    url: 'form/form/saveForm',
    data: data
  })
}

/**
 * @description 保存表单页面设计内容
 */
export const editFormJson = (data) => {
  return request.post({
    url: 'form/form/editFormJson',
    data: data
  })
}

/**
 * @description 获取自定义表单实例数据
 */
export const getFormData = (recordId, formId, isPreview) => {
  return request.postXww({
    url: 'form/form/getFormData',
    params: { recordId: recordId, formId: formId, isPreview: isPreview }
  })
}

/**
 * @description 保存自定义表单记录
 */
export const saveFormData = (data) => {
  return request.post({
    url: 'form/form/saveFormData',
    data: data
  })
}

/**
 * @description 删除自定义表单记录
 */
export const delFormData = (recordId, formId) => {
  return request.postXww({
    url: 'form/form/delFormData',
    params: { recordId: recordId, formId: formId }
  })
}

/**
 * @description 批量删除自定义表单记录
 */
export const batchDelFormData = (ids, formId) => {
  return request.postXww({
    url: 'form/form/batchDelFormData',
    params: { ids: ids, formId: formId }
  })
}

/**
 * @description 查询引用实体表一条数据
 */
export const getRefEntityShowText = (entId, recordId) => {
  return request.postXww({
    url: 'form/form/getRefEntityShowText',
    params: { recordId: recordId, entId: entId }
  })
}

/**
 * @description  查询某实体对应的所有发布的表单
 */
export const getFormsByEntId = (entId) => {
  return request.postXww({
    url: 'form/form/getListByEntId',
    params: { entId: entId }
  })
}

/**
 * @description 分页查询引用实体表数据
 */
export const selectRefEntity = (data) => {
  return request.post({
    url: 'form/form/selectRefEntity',
    data: data
  })
}
